<?php

header('Content-Type: text/xml');
 echo '<?xml version="1.0" encoding="utf-8"?>
<usagers>';
 ?>

<?php 

 require_once("../test/php_connect.php");
 require_once("../lib/fonctions_requete_sql.php");
 require_once("../lib/tableau_association.php");
$connexion = new PDO('mysql:host='.$PARAM_hote.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$id=$_POST["id"];
//$id=9;

$sql="SELECT * FROM usager INNER JOIN etablissement ON etablissement.id_etablissement=usager.id_etablissement 
							INNER JOIN adresse ON adresse.id_adresse=etablissement.id_adresse
							INNER JOIN coordonnee ON etablissement.id_coordonnee=coordonnee.id_coordonnee
							INNER JOIN ville ON adresse.id_ville= ville.id_ville WHERE id_usager=$id";
$query = $connexion->query($sql);


/*récupération des informations de base de l'usager*/
foreach($query as $row){
	echo "<usager>";
	$id_etab_facturation = $row['id_etablissement_facturation'];
	$id_usager = $row['id_usager'];
	foreach($tab_correspondance_usager as $key=>$value)
		echo '<'.$key.">".$row[$value]."</".$key.">";
	

	
	/*récupération des coordonnées de l'etablissement de facturation */
	$query2 = getEtablissement($connexion,$id_etab_facturation);
	foreach($query2 as $row2){
		foreach($tab_facturation_usager as $key=>$value)
		echo '<'.$key.">".$row2[$value]."</".$key.">";
	}
	
	/*recuperation des contacts de l'usager*/
	$query3= getCommentaire($connexion,"id_usager",$id_usager,"contact_usager");
	echo "<tableau_contact_prospect type='tab' table='tableau_contact_prospect'>";
	$nb_comm = 1;
	foreach($query3 as $row3){
		
		echo "<commentaire>";
			echo "<nom_contact_prospect".$nb_comm.">".$row3['nom']."</nom_contact_prospect".$nb_comm.">";
			echo "<fonction_contact_prospect".$nb_comm.">".$row3['fonction']."</fonction_contact_prospect".$nb_comm.">";
			echo "<telephone_contact_prospect".$nb_comm.">".$row3['telephone']."</telephone_contact_prospect".$nb_comm.">";
			echo "<comm_contact_prospect".$nb_comm.">".$row3['commentaire']."</comm_contact_prospect".$nb_comm.">";
		echo "</commentaire>";
		$nb_comm = $nb_comm+1;
	}
	echo "</tableau_contact_prospect>";
	
	
	/*recuperation des commentaires a propos de l'usager*/
	$query4= getCommentaire($connexion,"id_usager",$id_usager,"commentaire_usager");
	echo "<rdv_prospect type='tab' table='rdv_prospect'>";
	$nb_comm = 1;
	foreach($query4 as $row4){
		
		echo "<commentaire>";
			echo "<date_rdv_prospect".$nb_comm.">".$row4['date']."</date_rdv_prospect".$nb_comm.">";
			echo "<inter_rdv_prospect".$nb_comm.">".$row4['interloc']."</inter_rdv_prospect".$nb_comm.">";
			echo "<comm_rdv_prospect".$nb_comm.">".$row4['commentaire']."</comm_rdv_prospect".$nb_comm.">";
		echo "</commentaire>";
		$nb_comm = $nb_comm+1;
	}
	echo "</rdv_prospect>";
	echo "</usager>";
 }
echo "</usagers>";
?>